import { fileURLToPath, URL } from 'node:url'

import { loadEnv, defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'


export default ({ mode }) => {
  let env = loadEnv(mode, process.cwd());

// https://vitejs.dev/config/
  return  defineConfig({
    plugins: [
      vue(),
      vueDevTools(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      open: true,
      proxy: {
        [env.VITE_PATH_PREFIX]: {
          rewrite: (path) => path.replace(env.VITE_PATH_PREFIX, ""),
          target: "http://127.0.0.1:9090",
          // target: "http://124.71.4.1:8082",
          changeOrigin: true,
        },
      },
    },
  })
}
